<template>
    <div>
        <page-header title="数据备份" />
        <page-main>
            <el-card class="box-card">
                <el-row>
                    <el-col span="10" offset="4">
                        <el-form ref="form" :model="form" size="mini" label-width="80px">
                            <el-form-item label="备份名称">
                                <el-input v-model="form.name" placeholder="请输入备份名称"></el-input>
                            </el-form-item>
                        </el-form>
                    </el-col>
                    <el-col span="8" offset="1">
                        <el-button class="pull-right" type="primary" size="mini" icon="el-icon-caret-right" @click="openFullScreen">开始备份</el-button>
                        <el-button class="pull-right" type="success" size="mini" icon="el-icon-upload">上传备份文件</el-button>
                    </el-col>
                </el-row>
                <hr>
                <el-table :data="tableData" border style="width: 100%;">
                    <el-table-column label="序号" type="index" align="center" show-overflow-tooltip width="50px">
                    </el-table-column>
                    <el-table-column label="名称" prop="name">
                    </el-table-column>
                    <el-table-column prop="date" label="备份时间">
                    </el-table-column>
                    <el-table-column prop="size" label="数据大小(M)">
                    </el-table-column>
                    <el-table-column label="操作">
                        <template slot-scope="scope">
                            <el-button size="mini" type="warning" @click="handleEdit(scope.$index, scope.row)">恢复</el-button>
                            <el-button size="mini" type="primary" @click="handleEdit(scope.$index, scope.row)">下载</el-button>
                            <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除
                            </el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <el-pagination
                    :current-page.sync="currentPage"
                    :page-size="100"
                    :total="1000"
                    layout="total, prev, pager, next"
                    @current-change="handleCurrentChange"
                    @size-change="handleSizeChange">
                </el-pagination>
            </el-card>
        </page-main>
    </div>
</template>

<script>
export default {
    name: 'dataBackUp',
    data() {
        return {
            form: {},
            currentPage: 1,
            tableData: [{
                date: '2021-05-02',
                name: '文件一'
            }, {
                date: '2021-05-04',
                name: '文件二'
            }, {
                date: '2021-05-01',
                name: '文件三'
            }, {
                date: '2021-05-03',
                name: '文件四'
            }]
        }
    },
    methods: {
        handleEdit(index, row) {
            console.log(index, row)
        },
        handleDelete(index, row) {
            console.log(index, row)
        },
        handleSizeChange(val) {
            console.log(`每页 ${val} 条`)
        },
        handleCurrentChange(val) {
            console.log(`当前页: ${val}`)
        },
        openFullScreen() {
            const loading = this.$loading({
                lock: true,
                text: '数据备份中',
                spinner: 'el-icon-loading',
                background: 'rgba(0, 0, 0, 0.7)'
            })
            setTimeout(() => {
                loading.close()
            }, 2000)
        }
    }
}
</script>

<style>
.text {
    font-size: 14px;
}
.item {
    margin-bottom: 18px;
}
.clearfix::before,
.clearfix::after {
    display: table;
    content: "";
}
.clearfix::after {
    clear: both;
}
.box-card {
    width: 100%;
}
</style>

